package com.kun.web.controller;

import com.kun.utils.AjaxResult;
import com.kun.domain.SysUser;
import com.kun.service.service.LoginService;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping
public class LoginController {

    private final LoginService loginService;

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping("/login")
    public ResponseEntity<AjaxResult> login(@Validated @RequestBody SysUser user) {
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("token", loginService.login(user));
        return AjaxResult.success(stringStringHashMap);
    }

}
